<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
	boolean showTotal = (Boolean)request.getAttribute("showTotal");
	String motiTypeId  = (String)request.getAttribute("motiTypeId");
	if(motiTypeId==null){
		motiTypeId="";
	}
	String msg = (String)request.getAttribute("msg");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>资源活动事件列表</title>
     <meta http-equiv="refresh" content="300" />
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<%@ include file="../include/table.jsp"%>
	<%@ include file="../include/tree.jsp"%>
	<%@ include file="../include/tooltip.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/calendar/zh_CN_WdatePicker.js"></script>
	<style type="text/css">
		.ztree {border: 1px solid #617775;background: #f0f6e4;width:220px;height:360px;overflow-y:scroll;overflow-x:auto;}
		.xTable{ display:block; float:left;width:100%; height:100%;}
		html,body {
			overflow-x:hidden;
		}
		table.newTable thead th{
			marigin:0;
			padding:0;
		}
		.newTable{
			border-bottom:1px solid #e9e9e9;
		}
		.xTable td{
			vertical-align:top;
		}
		.w-200{
			width:30%;
			float:left;
		}
		.w-500{
			float:right;
			width:70%;
		}
		.w-500 a{
			float:right;
			width:auto;
			background-position-x:0px;
			padding-left:0;
			text-decoration:none;
			cursor:pointer;
		}
		.w-500 a:hover{
			text-decoration:underline;
		}
		table.newTable td{
			height:auto;
			line-height:35px;
		}
		.titleTh td{
			line-height:16px !Important;
			color:#888;
			text-indent:12px;
			background:url(../../style/default/images/titleTh.gif) no-repeat left top;
			}
		.dataTd td{
			height:35px;
			line-height:35px;
			font-size:15px;
			font-weight:600;
			text-align:center;
			}
		.renlin{
			background:url(../style/default/bsm/images/ack.gif) no-repeat 12px 3px;
		}
		.clear_1{
			background:url(../style/default/bsm/images/confirm.gif) no-repeat 12px 3px;		
		}
		
	</style>
	<script type="text/javascript">
	var motiTypeId = '<%=motiTypeId%>';
	var map  = new Array();
	function datagrid(){
		var oTable=	$('#eventList').dataTable();
		oTable.fnPageChange("first",true);
		changeSearchValue();
	}
	function cancelAllCheck(){
		$("#dt_check_all").removeAttr("checked");
	}
	function changeSearchValue(){
		$.ajax({
			   type: "POST", 
			   url: "${pageContext.request.contextPath}/event/active-event!levelAndStatusData.action", //请求的action
			   data: "", //传的参数
			   dataType: 'json',
			   success: function(data){ //结果
				  	$("#eventlevel").html("全部("+data.eventlevel+")");
					$("#eventlevel2").html("轻微("+data.eventlevel2+")");
					$("#eventlevel3").html("警告("+data.eventlevel3+")");
					$("#eventlevel4").html("重要("+data.eventlevel4+")");
					$("#eventlevel5").html("严重("+data.eventlevel5+")");
					$("#status0").html("未认领("+data.status0+")");
					$("#status1").html("已认领("+data.status1+")");
			   }
		});
	}
	 //全选和取消全选
	    function allClick(isSigle)
	    {
	    	if(isSigle!=1) //如果是单选就不支持全选
  	    	{
  	    		var dt_check_all = $('#dt_check_all').attr("checked");
	  	    	var allCheckbox = $("input[name='dt_check']");
	  	    	if(dt_check_all)
	  	    	{
	  	    		
	  	    		allCheckbox.attr("checked",allCheckbox);  //全选
	  	    		$('#depmtList tbody tr').addClass('row_selected');  //背景色全选
	  	    	}else
	  	    	{
	  	    		allCheckbox.attr("checked",false);   //取消全选
	  	    		$('#depmtList tbody tr').removeClass('row_selected');  //背景色取消
	  	    	}
  	    	}
	    }
	$(function(){
		//加载grid
		var oTable=	$('#eventList').dataTable({
			"bProcessing": true, 
			"bServerSide": true,
			"sServerMethod": 'POST',
			"sAjaxSource":'${pageContext.request.contextPath}/event/active-event!list.action',
			"bPaginate": true,
			"bSort": true,
			"bFilter":false,
			"bJQueryUI":false,
			//"sScrollX":'100%',
			"sPaginationType": "full_numbers",
			"iDisplayLength":20,
			"sDom":'rt <"bottom"flpi>',
			"aLengthMenu": [[20, 30, 50, 100], [20, 30, 50, 100]],
			"aoColumns":[
				{"mDataProp":"checkbox","bSortable": false, "bVisible": motiTypeId=='', "aTargets": [ 0 ] },
				{"mDataProp":"op","bSortable": false, "bVisible": motiTypeId=='', "aTargets": [ 1 ] },
				{"mDataProp":"status","bSortable": true,
					"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
						var statusName = oData.statusName;
						var status= oData.status;
						var eventId = oData.id;
						var ss = "<a id='"+oData.id+"_s' onmouseout='closeIt();' rel='${pageContext.request.contextPath}/event/active-event!tooltipStatus.action?status="+status+"&eventId="+eventId+"' href='#'>"+ statusName +"</a>";
						$(nTd).html(ss);
				}},
				{"mDataProp":"levelName","bSortable": true,
					"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
						var levelName = oData.levelName;
						var level= oData.level;
						var ss = "<a id='"+oData.id+"_l' onmouseout='closeIt();' rel='${pageContext.request.contextPath}/event/active-event!tooltipLevel.action?level="+level+"' href='#'>"+ levelName +"</a>";
						$(nTd).html(ss);
				}},
				{"mDataProp":"msg","bSortable": false},
				{"mDataProp":"eventTypeName","bSortable": true},
				{"mDataProp":"resName","bSortable": true},
				{"mDataProp":"occurTime","bSortable": true},
				{"mDataProp":"count","bVisible": true},
				{"mDataProp":"id","bVisible":false}
			], 
			 "oLanguage": { 
			 				"sLengthMenu": "每页 _MENU_ 条",
			 		 		"sZeroRecords": "  ",
							"sInfo": "当前从 _START_ 到 _END_ 条,共 _TOTAL_ 条记录", 
							"sInfoEmpty": "没有找到记录",
							"oPaginate":{"sFirst":"首页","sPrevious":"上一页","sNext":"下一页","sLast":"尾页"}	
			},
		    "fnServerParams":function(aoData){
		    	
		    	var level = $("#level").val();
		    	var status = $("#status").val();
		    	if(level !='')
		    	{
		    		aoData.push({'name':'level','value':level});
		    	}
		    	if(status !='')
		    	{
		    		aoData.push({'name':'status','value':status});
		    	}
		    	aoData.push({'name':'motiTypeId','value':motiTypeId});
		    	
		    },
			"fnRowCallback":function( nRow, aData, iDisplayIndex, iDisplayIndexFull )
			{		
				var id= aData.id;
				map.push(id+"_l");
				map.push(id+"_s");
			},
			 "fnDrawCallback": function () {
				setTimeout('setValueToolTip()',800);
		    }
	});
		$('#eventList tbody td :checkbox').live('click', function (e) {
			 if(!$(this).attr("checked")){
				 cancelAllCheck();
			 }
		});
	
		
	});

	function setValueToolTip()
	{
	 	for(var i =0; i<map.length; i++) 
	 		$("#"+map[i]).cluetip({ sticky: true,  mouseOutClose: true, arrows: true, showTitle: false,
					  width:200
					  ,
					  closePosition: 'title',
					  cluetipClass: 'rounded',
					  clickThrough:false,
					  ajaxCache: false
					  
					});
	}
	function closeIt(){
		$(document).trigger('hideCluetip');
	}	
	
	//得到当前选中的
	function fnGetSelected() {   
		var selections = $("input[name='dt_check']:checked");
		return selections;
	} 
	
	function search(){
		var oTable=	$('#eventList').dataTable();
		oTable.fnPageChange("first",true);
		changeSearchValue();
	}
	
	function eventDown(){
		var level = $("#level").val();
    	var status = $("#status").val();
		window.location="${pageContext.request.contextPath}/event/event-export!doExport.action?status="+status+"&level="+level;
	}
	function batchConfirm(){
		var rows = fnGetSelected();
		if(rows.length>0){
			var id = new Array(rows.length);
			var oTable =$('#eventList').dataTable();
			for(var i = 0 ; i<rows.length;i++){
				id[i] = rows[i].value;
			}
			//校验是否有权限
			$.ajax({
				   type: "POST", 
				   url: "${pageContext.request.contextPath}/event/active-event!handelAuth.action?id="+id, //请求的action
				   data: "", //传的参数
				   dataType: 'json',
				   success: function(data){ //结果
					   if(data == true){
						 //校验是否包含已认领事件
							$.ajax({
								   type: "POST", 
								   url: "${pageContext.request.contextPath}/event/active-event!confirmCheck.action?id="+id, //请求的action
								   data: $("#myform").serialize(), //传的参数
								   dataType: 'json',
								   success: function(data){ //结果
									   if(data == true){
										   var url ="iframe:event/active-event!delete.action?id="+id;
											var opt = { title: "清除活动事件",width:600,height:280,buttons: {}};
											getTopWin(window).openjBox(url,opt,'confirm-active-event',window);
									   }else{
										   datagrid();
										   getTopWin(window).getMessageBox().alert("包含已清除事件","提示");
									   }
								   }
							});
					   }else{
						   getTopWin(window).getMessageBox().alert("没有清除权限","提示");
					   }
				   }
			});
		}else{
			getTopWin(window).getMessageBox().alert("请选择一条数据","提示");
		}
	}
	function batchAck(){
		var rows = fnGetSelected();
		if(rows.length>0){
			var id = new Array(rows.length);
			var oTable =$('#eventList').dataTable();
			for(var i = 0 ; i<rows.length;i++){
				id[i] = rows[i].value;
			}
			//校验是否有权限
			$.ajax({
				   type: "POST", 
				   url: "${pageContext.request.contextPath}/event/active-event!handelAuth.action?id="+id, //请求的action
				   data: "", //传的参数
				   dataType: 'json',
				   success: function(data){ //结果
					   if(data == true){
						 //校验是否包含已认领事件
							$.ajax({
								   type: "POST", 
								   url: "${pageContext.request.contextPath}/event/active-event!ackCheck.action?id="+id, //请求的action
								   data: $("#myform").serialize(), //传的参数
								   dataType: 'json',
								   success: function(data){ //结果
									   if(data == true){
										   	var url ="iframe:event/active-event!input.action?id="+id;
											var opt = { title: "认领活动事件",width:600,height:180,buttons: {}};
											getTopWin(window).openjBox(url,opt,'ack-active-event',window);
									   }else{
										   datagrid();
										   getTopWin(window).getMessageBox().alert("包含已认领事件","提示");
									   }
								   }
							});
					   }else{
						   getTopWin(window).getMessageBox().alert("没有认领权限","提示");
					   }
				   }
			});
		}else{
			getTopWin(window).getMessageBox().alert("请选择一条数据","提示");
		}
}
	function onclickLevel(level){
		$("#level").val(level);
		$("#status").val("");
		search();
	}
	function onclickStatus(status){
		$("#status").val(status);
		$("#level").val("");
		search();
	}
	function confirm(id){
		//校验是否有权限
		$.ajax({
			   type: "POST", 
			   url: "${pageContext.request.contextPath}/event/active-event!handelAuth.action?id="+id, //请求的action
			   data: "", //传的参数
			   dataType: 'json',
			   success: function(data){ //结果
				   if(data == true){
					   var url ="iframe:event/active-event!singleConfirm.action?id="+id;
						var opt = { title: "事件清除",width:560,height:300,buttons: {}};
						getTopWin(window).openjBox(url,opt,'active-event-singleConfirm',window);
				   }else{
					   getTopWin(window).getMessageBox().alert("没有清除权限","提示");
				   }
			   }
		});
	}
	function ack(id){
		//校验是否有权限
		$.ajax({
			   type: "POST", 
			   url: "${pageContext.request.contextPath}/event/active-event!handelAuth.action?id="+id, //请求的action
			   data: "", //传的参数
			   dataType: 'json',
			   success: function(data){ //结果
				   if(data == true){
					   var url ="iframe:event/active-event!singleAck.action?id="+id;
						var opt = { title: "事件认领",width:560,height:300,buttons: {}};
						getTopWin(window).openjBox(url,opt,'active-event-singleAck',window);
				   }else{
					   getTopWin(window).getMessageBox().alert("没有认领权限","提示");
				   }
			   }
		});
	}
	function showMessage(message){
		window.setTimeout(function () { $.jBox.tip(message, 'success'); }, 100);
	}
	</script>
  </head>
  
<body style="overflow-x:hidden;" >
<c:if test="${isPlay}">
  <embed id="soundControl" src="/bsm/jsp/event/media/event${maxLevel}.mp3" style="display:none;" mastersound hidden="true" loop="false" autostart="true"></embed>
</c:if>

  <% if(showTotal){ %>
    <div>
		<h2 class="title-h2" onclick="accordionDiv(this)" ><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>事件动态</h2> 
		<table id="testTable" cellpadding="0" cellspacing="0" class="display dataTable newTable" style="display: none;">
				<thead>
					<tr class="changecolor" style="font-family:arial;">
					    <th class="sorting_disabled" colspan="1" rowspan="1" style="width:14%;">&nbsp;</th>
						<th class="sorting_disabled" colspan="1" rowspan="1" style="width:14%;">${viewData[0].title}</th>
						<th class="sorting_disabled" colspan="1" rowspan="1" style="width:14%;">${viewData[1].title}</th>
						<th class="sorting_disabled" colspan="1" rowspan="1" style="width:14%;">${viewData[2].title}</th>
						<th class="sorting_disabled" colspan="1" rowspan="1" style="width:14%;">${viewData[3].title}</th>
						<th class="sorting_disabled" colspan="1" rowspan="1" style="width:14%;">${viewData[4].title}</th>
						<th class="sorting_disabled" colspan="1" rowspan="1" style="width:14%;">${viewData[5].title}</th>
					</tr>
			    </thead>
			    <tbody>
			    		<tr class="even titleTh" style="background:#fff;">
			    			<td  style="text-align: center; color:#000;" >
								新产生
							</td>
			    			<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[0].created}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[1].created}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[2].created}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[3].created}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[4].created}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[5].created}
							</td>
						</tr>
						<tr class="even titleTh">
			    			<td  style="text-align: center; color:#000;" >
								认领
							</td>
			    			<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[0].acked}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[1].acked}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[2].acked}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[3].acked}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[4].acked}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[5].acked}
							</td>
						</tr>
						<tr class="even titleTh" style="background:#fff;">
			    			<td  style="text-align: center; color:#000;" >
								手动清除
							</td>
			    			<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[0].manClosed}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[1].manClosed}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[2].manClosed}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[3].manClosed}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[4].manClosed}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[5].manClosed}
							</td>
						</tr>
						<tr class="even titleTh">
			    			<td  style="text-align: center; color:#000;" >
								自动清除
							</td>
			    			<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[0].autoClosed}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[1].autoClosed}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[2].autoClosed}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[3].autoClosed}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[4].autoClosed}
							</td>
							<td  style="text-align: center; font-size:14px; font-family:arial; color:#000;" >
								${viewData[5].autoClosed}
							</td>
						</tr>
			    </tbody>
		</table>
	</div>
    <div>
    <%} %>
     <h2 class="title-h2" style="border-right:#e9e9e9 1px solid"><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>活动事件列表</h2> 	
		 	<div class="toolbar w-200" id = "toolbar" style="display:<%=showTotal ? "block":"none" %>;">
		 		<a class="page_add renlin" href="javascript:batchAck();">认领</a>
		 		<a class="page_delete clear_1" href="javascript:batchConfirm();">清除</a>
		 		<a class="page_excel" href="javascript:eventDown();">导出</a>
			</div>
			<div class="toolbar w-500" style="display:<%=showTotal ? "block":"none" %>;">
				<input type="hidden" id="level" name="level"/>
				<input type="hidden" id="status" name="status"/>
		 		<a onclick="onclickLevel('');"><div id="eventlevel">全部(${allLevel})</div></a>
		 		<a id="eventlevel2" class="eventlevel2" onclick="onclickLevel('2');"><div id="eventlevel2">轻微(${level2})</div></a>
		 		<a id="eventlevel3" class="eventlevel3" onclick="onclickLevel('3');"><div id="eventlevel3">警告(${level3})</div></a>
		 		<a id="eventlevel4" class="eventlevel4" onclick="onclickLevel('4');"><div id="eventlevel4">重要(${level4})</div></a>
		 		<a id="eventlevel5" class="eventlevel5" onclick="onclickLevel('5');"><div id="eventlevel5">严重(${level5})</div></a>
		 		<a class="status0" onclick="onclickStatus('0');"><div id="status0">未认领(${status0})</div></a>
		 		<a class="status1" onclick="onclickStatus('1');"><div id="status1">已认领(${status1})</div></a>
			</div>
		<div>
		
		<table id="eventList" width="100%" cellpadding="0" cellspacing="0" border="0" class="display">
			<thead>
				<tr>
					<th width="20">&nbsp;&nbsp;<input type='checkbox' name='dt_check_all'
						id="dt_check_all" onclick="allClick()" /></th>
					<th width="20">操作</th>
					<th width="20">状态</th>
					<th width="20">级别</th>
					<th>事件内容</th>
					<th width="200">事件类别</th>
					<th width="200">资源名称</th>
					<th width="120">产生时间</th>
					<th width="20">统计次数</th>
				</tr>
			</thead>
		</table>
		</div>
   </div>

  </body>
</html>
